package gold.digger;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LCJZOF17 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public String minWindow(String s, String t) {
            // 滑动窗口, 维护合法区间, 判断区间长度是否更小, 记录区间头与区间长度
            int[] cnts = new int[100];
            for (char c : t.toCharArray()) cnts[c - 'A']++;
            char[] cs = s.toCharArray();
            int num = t.length(), start = 0, ans = cs.length + 1, pos = 0;

            for (int i = 0; i < cs.length; ++i) {
                if (--cnts[cs[i] - 'A'] >= 0) num--;
                while (start < cs.length && cnts[cs[start] - 'A'] < 0) cnts[cs[start++] - 'A']++;
                if (num == 0 && i - start + 1 < ans) {
                    ans = i - start + 1;
                    pos = start;
                }
            }
            return ans == cs.length + 1 ? "" : s.substring(pos, pos + ans);
        }
    }


    public void run() {
        int[] arr = InputUtil.toIntegerArray("[1,2,3]");
        System.out.println(new Solution().toString());
    }

    public static void main(String[] args) throws Exception {
        LCJZOF17 an = new LCJZOF17();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
